<?php

//UMA new
namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use App\Models\InputItem as InputModel;

class InputGroup extends JsonResource
{
    /**
     * 把 model 转换成 array.
     * model 変換 array
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'name' => $this->input_group,
            'items' => InputItem::collection($this->items->filter(function ($item) {
                return !in_array($item->identifier, InputModel::HIDDEN_ITEMS);
            })->pluck(null, 'identifier')),
        ];
    }
}
